package com.example.mapper;

import com.example.pojo.Defect;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DefectMapper {

    //查询所有缺陷种类
    @Select("select * from defect")
    public List<Defect> findAll();

    //查询defect表中isMachine为0的数据
    @Select("select * from defect where isMachine = 0")
    public List<Defect> findNoMachine();

    //查询defect表中isMachine为1的数据
    @Select("select * from defect where isMachine = 1")
    public List<Defect> findMachine();

    //新增
    @Insert("insert into defect (defectID,defectName, isMachine, defectGrade, create_time, update_time) values (#{defectID},#{defectName},#{isMachine},#{defectGrade},#{createTime},#{updateTime})")
    void insert(Defect defect);

    //根据id删除缺陷种类
    @Delete("delete from defect where defectID = #{defectID}")
    void deleteById(Integer defectID);

    //修改
    @Update("update defect set defectName = #{defectName},isMachine = #{isMachine},defectGrade = #{defectGrade},update_time = #{updateTime} where defectID = #{defectID}")
    void update(Defect defect);

    //获取所有isMachine为0的defectName
    @Select("select defectName from defect where isMachine = 0")
    public List<String> getAllNames();

    //获取所有isMachine为1的defectName
    @Select("select defectName from defect where isMachine = 1")
    public List<String> getAllMachineNames();

    //根据id获取名称
    @Select("select defectName from defect where defectID = #{defectID}")
    String getDefectNameById(Integer defectID);
}
